import { Component, ChangeDetectorRef } from '@angular/core';
import { IonicPage } from 'ionic-angular';

// service
import { HideBarsService } from '../../../providers/utils/hideBars.service';

/**
 * 服务协议
 */
@IonicPage()
@Component({
  selector: 'page-service-agreement',
  templateUrl: 'service-agreement.html'
})
export class ServiceAgreementPage {

  title: string = '用户支付服务协议';
  // 滚动
  private scroll_animate: boolean = false;
  private old_scrollTop = 0;
  constructor(
    private ref: ChangeDetectorRef,
    private hideBars: HideBarsService
  )
  {}

  /*** 当页面即将进入并成为活动页面时运行。
   * */
  ionViewWillEnter()
  {
    this.hideBars.changeTabBarsElementBottom('-5rem');
  }

  /*** 离开取消订阅
   * */
  ionViewWillLeave()
  {
    this.hideBars.changeTabBarsElementBottom('0');
  }
  /***
   * 滚动监听,处理头部导航
   * */
  onScroll($event: any): void{
    let scrollTop = $event.scrollTop;
    if (scrollTop > 50 && (this.old_scrollTop - scrollTop) < 0) {

      if (!this.scroll_animate) {
        this.scroll_animate = true;
      }

    } else {
      this.scroll_animate = false;
    }

    this.old_scrollTop = scrollTop;
    this.ref.detectChanges();
  }

}
